package com.mall.shopping.services;


import com.mall.shopping.IProductCateService;
import com.mall.shopping.constants.ShoppingRetCode;
import com.mall.shopping.converter.ProductCateConverter;
import com.mall.shopping.dal.entitys.ItemCat;
import com.mall.shopping.dal.persistence.ItemCatMapper;
import com.mall.shopping.dto.AllProductCateResponse;
import lombok.extern.log4j.Log4j;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import tk.mybatis.mapper.entity.Example;

import java.util.List;

@Log4j
@Service
public class IProductCateServiceImpl implements IProductCateService {

    @Autowired
    ItemCatMapper itemCatMapper;
    @Autowired
    ProductCateConverter converter;

    @Override
    public AllProductCateResponse getAllProductCate() {
        AllProductCateResponse response = new AllProductCateResponse();
        try {
            Example example = new Example(ItemCat.class);
            example.createCriteria().andEqualTo("status", 1);
            List<ItemCat> itemCats = itemCatMapper.selectByExample(example);
            response.setProductCateDtoList(converter.items2Dto(itemCats));
            response.setCode(ShoppingRetCode.SUCCESS.getCode());
            response.setMsg(ShoppingRetCode.SUCCESS.getMessage());
        } catch (Exception e) {
            response.setCode(ShoppingRetCode.SYSTEM_ERROR.getCode());
            response.setMsg(ShoppingRetCode.SYSTEM_ERROR.getMessage());
        }
        return response;
    }
}
